import LoginPage from '../../pages/login'
import mainPage from '../../pages/mainPage'

// Cypress.Commands.add('login', (username, pwd) => {
//   cy.get('input[name=username]').type(username)
//   cy.get('input[name=password]').type(`${pwd}{enter}`)
// })

context('登录测试， PO模式', function () {
  /**
   * 自定义测试命令
   */
  // Cypress.Commands.add('testSelf', function () {
  //   cy.log(username + '===' + pwd)
  // })

  const username = 'jane.lane'
  const pwd = 'password123'

  it('登录成功', function () {
    const loginInstance = new LoginPage()

    loginInstance.visitPage()
    // loginInstance.login(username, pwd)
    // cy.url().should('include', '/dashboard')
    loginInstance.isTargetPage()
    // cy.testSelf()
    // 调用Custom Commands 的命令
    cy.login(username, pwd)
    cy.url().should('include', '/dashboard')

    const mainInstance = new mainPage()

    mainInstance.isTargetPage()
    mainInstance.welComeText.should('contain', 'jane.lane')
  })
})
